package com.yueqian.sort;

import java.util.Arrays;

public class SelectionSort2 {
    public static void main(String[] args) {
        int[] a = {8, 9, 7, 5, 8, 2, 6, 7, 3, 0, 9};
        selectionSort(a);
        System.out.println(Arrays.toString(a));

    }

    public static void selectionSort(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            //获取起始位置中元素内容
            int minNum = a[i];
            //记录最小元素位置j
            int minIndex = i;
            for (int j = i + 1; j < a.length; j++) {
                if (a[j] < minNum) {
                    minNum = a[j];
                    minIndex = j;
                }
            }
            //交换元素
            int temp = a[i];
            a[i] = a[minIndex];
            a[minIndex] = temp;

        }

    }
}
